package cn.qiyu5522.controller;


import cn.qiyu5522.constant.SystemConstants;
import cn.qiyu5522.domain.DTO.CommentDTO;
import cn.qiyu5522.domain.entity.ResponseResult;
import cn.qiyu5522.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author Tonkey
 * @since 2024-04-13
 */

@Api(tags = "评论相关接口")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @ApiOperation(value = "根据文章ID分页查询文章下评论列表",notes = "根据文章ID分页查询该文章下的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页号"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "articleId", value = "文章编号")
    })
    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize){
        return commentService.commentList(articleId,pageNum,pageSize,SystemConstants.ARTICLE_COMMENT);
    }



    @ApiOperation(value = "添加评论",notes = "评论DTO接收，添加评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "commentDTO",value = "评论DTO类"),
    })
    @PostMapping
    public ResponseResult addComment(@RequestBody CommentDTO commentDTO){
        return commentService.addComment(commentDTO);
    }

    @ApiOperation(value = "获取友链下的评论",notes = "根据文章ID，分页查询友链下的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页号"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "articleId", value = "文章编号")
    })
    @GetMapping("/linkCommentList")
    public ResponseResult linkCommentList(Long articleId, Integer pageNum, Integer pageSize){
        return commentService.commentList(articleId, pageNum, pageSize, SystemConstants.LINK_COMMENT);
    }

}
